package com.yuqian.JavaSe.thread.cands;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class SCallable {
	public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException {
		ExecutorService es = Executors.newCachedThreadPool();
		Callable<String> call =new Callable<String>() {
			public String call() throws Exception {
				return "Callable Test";
			}
		};
		
		FutureTask<String> future = new FutureTask<String>(call);
		// 第一种方式
		/*Future<String> stest =es.submit(call);
		String result =(String)stest.get(10, TimeUnit.MILLISECONDS);
		System.out.println(result);*/
		
		//第二种方式
		 es.submit(future);
		System.out.println(future.get());
		es.shutdown();
	}
}
